package br.com.fiap.trabalho.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCConnectionManager {
	
	private static final String DERBY_CONNECTION_URL = "jdbc:derby:simpleDB;create=true";
	
	public static Connection getConnection() throws Exception {
		return getDerbyConnection();
	}
	
	public static void closeConnection(Connection connection) {
		
		if (connection == null) {
			return;
		}
		
		try {
			connection.close();
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("Erro ao fechar a conexao com o BD.");
		}
	}
	
	private static Connection getDerbyConnection() throws Exception {
		Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
		return DriverManager.getConnection(DERBY_CONNECTION_URL, "TrabalhoPersistenciaJava", "TrabalhoPersistenciaJava");
	}

}
